<?php
class CoreWidget extends CWidget
{
    /**
     * 清理cookie
     * @param  $name
     */
    protected function _cookiesRemove ($name)
    {
        $cookie = Yii::app()->request->getCookies();
        unset($cookie[$name]);
    }

    //获取用户 角色的前端操作动作 返回  true  与 false;
    public function getRole($role,$role_salt,$action){
        if($role > 0){
            //加盐解密对比
            $jm = Xtutuquan::encryption($role_salt,1);
            $jm_arr = explode('|',$jm);
            if($role ==$jm_arr[1]){
                //匹配成功 去role表取得这个role的前台frontend 用于的权限
                $role_priv = RolePriv::model()->getRole($role,$action,'frontend');
                return $role_priv;
            }else{
                //永久封账号
                $user_info = User::model()->findByPk($jm_arr[0]);
                $user_info->status = 0;
                $user_info->update();
                Yii::app()->user->logout();
                //销毁cookie
                $this->_cookiesRemove('auto');
                Yii::app()->getRequest()->redirect(Yii::app()->homeUrl);
            }
        }
    }
}